package com.kdtech.analyse.news.ulinix;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

import com.kdtech.entity.crawler.UrlMeta;
import com.kdtech.entity.data.NewsMeta;
import com.kdtech.utils.DateUtils;
import com.kdtech.utils.HtmlCleaner;
import com.kdtech.utils.NumberUtils;
import com.kdtech.utils.StringUtils;
import com.kdtech.analyse.AnalyseNews;
/**
 * axpaz
 */
public class AxpazBbsAnalyse implements AnalyseNews {

	
	public boolean isDetailPage(String url){
		boolean bRet=false;
		String[] regex={
				"http://www.axpaz.cn/bbs/forum.php\\?mod=viewthread&tid=[0-9]*",
				"http://www.axpaz.cn/bbs/forum.php\\?from=portal&mod=viewthread&tid=[0-9]*",
				};
		for (int i=0; i < regex.length; i++) {
			if (url.matches(regex[i])) {
				return true;
			}
		}
		return bRet;
	}

	
	public NewsMeta parserHtml(UrlMeta urlMeta) {
		NewsMeta bbs=new NewsMeta();
		if (urlMeta.getHtml() == null) {
		}		
		String htmltxt=urlMeta.getHtml();
		String url=urlMeta.getUrl();		
		if(!isDetailPage(url)){
		}				
		bbs.setUrl(url);		
		String title=null;
		String content=null;
		Long date=null;
		String author=null;
		Integer clickNum=0;
		Integer commentNum=0;

		Document doc=Jsoup.parse(htmltxt);
		title = doc.select("h1.ph").text();
		if(StringUtils.isBlank(title)){
			title = doc.select("span#thread_subject").text();
		}
		date = DateUtils.matchDate(doc.select("p.xg1").text());
		if(date==null){
			date = DateUtils.matchDate(doc.select("div.authi").text());
		}
		content = doc.select("td.t_f").text();
		if(StringUtils.isBlank(title)){
		}
		bbs.setClickNum(clickNum);
		bbs.setCommentNum(commentNum);
		bbs.setTitle(StringUtils.trimSpace(title));
		bbs.setContent(content);
		bbs.setDate(date);	
		bbs.setAuthor(author);
		bbs.setUpdateUrl(url);
		return bbs;
	}
	
	public NewsMeta Update(NewsMeta meta) {
		String url=meta.getUpdateUrl();
		if (StringUtils.isNotBlank(url)){
//			UrlMeta urlMeta=CrawlHTML.responseToURL(url);
//			return parserHtml(urlMeta);
		}
		return null;
	}
    
	
}
